package com.platform.usercenter.controller;

import com.platform.common.core.utils.poi.ExcelUtil;
import com.platform.common.core.web.controller.BaseController;
import com.platform.common.core.web.domain.MbResult;
import com.platform.common.core.web.page.TableDataInfo;
import com.platform.usercenter.domain.SysModelRoleFunction;
import com.platform.usercenter.service.ISysModelRoleFunctionService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 角色职能Controller
 *
 * @author wcs
 * @date 2025-09-21
 */
@RestController
@RequestMapping("/roleFunction")
public class SysModelRoleFunctionController extends BaseController {
    @Resource
    private ISysModelRoleFunctionService sysModelRoleFunctionService;

    /**
     * 查询角色职能列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SysModelRoleFunction sysModelRoleFunction) {
        startPage();
        List<SysModelRoleFunction> list = sysModelRoleFunctionService.selectSysModelRoleFunctionList(sysModelRoleFunction);
        return getDataTable(list);
    }

    /**
     * 导出角色职能列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysModelRoleFunction sysModelRoleFunction) {
        List<SysModelRoleFunction> list = sysModelRoleFunctionService.selectSysModelRoleFunctionList(sysModelRoleFunction);
        ExcelUtil<SysModelRoleFunction> util = new ExcelUtil<SysModelRoleFunction>(SysModelRoleFunction.class);
        util.exportExcel(response, list, "角色职能数据");
    }

    /**
     * 获取角色职能详细信息
     */
    @GetMapping(value = "/{id}")
    public MbResult<SysModelRoleFunction> getInfo(@PathVariable("id") Long id) {
        return MbResult.success(sysModelRoleFunctionService.selectSysModelRoleFunctionByUserId(id));
    }

    /**
     * 新增角色职能
     */
    @PostMapping
    public MbResult<Integer> add(@RequestBody SysModelRoleFunction sysModelRoleFunction) {
        return MbResult.success(sysModelRoleFunctionService.insertSysModelRoleFunction(sysModelRoleFunction));
    }

    /**
     * 修改角色职能
     */
    @PutMapping
    public MbResult<Integer> edit(@RequestBody SysModelRoleFunction sysModelRoleFunction) {
        return MbResult.success(sysModelRoleFunctionService.updateSysModelRoleFunction(sysModelRoleFunction));
    }

    /**
     * 删除角色职能
     */
    @DeleteMapping("/{ids}")
    public MbResult<Integer> remove(@PathVariable Long[] ids) {
        return MbResult.success(sysModelRoleFunctionService.deleteSysModelRoleFunctionByIds(ids));
    }
}
